﻿#region Copyright (c) Nicola Gallo All rights reserved.
/*
 * All rights reserved. Reproduction of trasmission of this file, or a portion thereof,
 * is forbidden without prior written permission of Nicola Gallo.
 * 
 * Author: Nicola Gallo
 * Date: 09/04/2011
 * 
 * */
#endregion
namespace PrismMVC.ModuleA.Data
{
    //.NET References
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Linq;
    using System.Text;

    /// <summary>
    /// Defines a person class.
    /// </summary>
    public class Person : INotifyPropertyChanged
    {
        //Events

        /// <summary>
        /// Occurs when a property value changes.
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;

        //Fields

        private String _personID;
        private String _name;
        private String _surename;
        private String _city;
        private String _address;

        //Constructors

        /// <summary>
        /// Creates a new instance of <see cref="Person"/>.
        /// </summary>
        /// <param name="personID">Person identifier.</param>
        public Person(string personID)
        {
            if (String.IsNullOrWhiteSpace(personID))
            {
                throw new ArgumentException("Invalid person identifier.");
            }
        }

        //Properties

        /// <summary>
        /// Gets the person identifier.
        /// </summary>
        public String PersonID
        {
            get { return this._personID; }
            private set 
            {
                if (this._personID != value)
                {
                    this._personID = value;
                    this.OnPropertyChanged("PersonID");
                }
            }
        }

        /// <summary>
        /// Gets/Sets the name.
        /// </summary>
        public String Name
        {
            get { return this._name; }
            set 
            {
                if (this._name != value)
                {
                    this._name = value;
                    this.OnPropertyChanged("Name");
                } 
            }
        }

        /// <summary>
        /// Gets/Sets the surename.
        /// </summary>
        public String Surename
        {
            get { return this._surename; }
            set 
            {
                if (this._surename != value)
                {
                     this._surename = value;
                     this.OnPropertyChanged("Surename");
                } 
            }
        }

        /// <summary>
        /// Gets/Sets the city.
        /// </summary>
        public String City
        {
            get { return this._city; }
            set 
            {
                if (this._city != value)
                {
                    this._city = value;
                    this.OnPropertyChanged("City");
                } 
            }
        }

        /// <summary>
        /// Gets/Sets the address.
        /// </summary>
        public String Address
        {
            get { return this._address; }
            set 
            {
                if (this._address != value)
                {
                    this._address = value;
                    this.OnPropertyChanged("Address");
                } 
            }
        }

        //Methods

        /// <summary>
        /// Raises the <see cref="PresentationModel.PropertyChanged"/> event for the input property name.
        /// </summary>
        /// <param name="propertyName"></param>
        protected void OnPropertyChanged(String propertyName)
        {
            if (!string.IsNullOrWhiteSpace(propertyName))
            {
                PropertyChangedEventHandler propertyChangedHnd = this.PropertyChanged as PropertyChangedEventHandler;
                if (propertyChangedHnd != null)
                {
                    propertyChangedHnd(this, new PropertyChangedEventArgs(propertyName));
                }
            }
        }
    }
}